package com.hmdp.common.config;

import com.hmdp.common.interceptor.RefreshTokenInterceptor;
import com.hmdp.common.interceptor.UserLoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author WDs , wds8.24@outlook.com
 * @version 1.0
 * @since 2023-01-07 15:28
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        添加拦截器并控制拦截器的执行顺序
        registry.addInterceptor(new RefreshTokenInterceptor(redisTemplate)).order(1);
        registry.addInterceptor(new UserLoginInterceptor())
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/user/code")
                .excludePathPatterns("/blog/hot")
                .excludePathPatterns("/shop/**").order(2);
    }
}
